package com.wei.web.demo.user.security;

import jakarta.servlet.http.HttpServletRequest;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.web.firewall.FirewalledRequest;
import org.springframework.security.web.firewall.RequestRejectedException;
import org.springframework.security.web.firewall.StrictHttpFirewall;


/**
 * This is intended to suppress the stacktrace caused by {@link RequestRejectedException}.
 *
 * @author Robin Yang
 * @since 2022/1/13
 */
@Slf4j
public class SuppressStackTraceHttpFirewall extends StrictHttpFirewall {

    @Override
    public FirewalledRequest getFirewalledRequest(HttpServletRequest request) {
        try {
            return super.getFirewalledRequest(request);
        } catch (RequestRejectedException e) {
            throw new RuntimeException(e.getMessage());
        }
    }

}